import { Entity, Column } from "typeorm";

import type { VARCHAR50_PG, PgIdTuple, VARCHAR255_PG, VARCHAR_PG, INTEGER_PG, BIGINT_PG, SMALLINT_PG } from "qqlx-core";
import { PgIdTupleGateway, ENUM_PG_TUPLE } from "qqlx-core";

import { TransformerInteger, TransformerBigInteger } from "@lib/orm.transfor.number";
import { TransformerVarchar, TransformerVarchar50, TransformerVarchar255 } from "@lib/orm.transfor.string";
import { TransformerBoolean } from "@lib/orm.transfor.boolean";

import { OwnerIdSchema } from "@/alpha/ext.id.base";
import { TransformerEnum } from "@lib/orm.transfor.enum";

@Entity({ name: PgIdTupleGateway.relations })
export class PgIdTupleSchema extends OwnerIdSchema implements PgIdTuple {
  @Column({
    transformer: new TransformerEnum(Object.values(ENUM_PG_TUPLE) as SMALLINT_PG[], ENUM_PG_TUPLE.OPTION1),
  })
  enum_small_int: ENUM_PG_TUPLE = ENUM_PG_TUPLE.OPTION1;

  @Column({ transformer: new TransformerVarchar50() })
  str_50: VARCHAR50_PG = "";

  @Column({ transformer: new TransformerVarchar255() })
  str_255: VARCHAR255_PG = "";

  @Column({ transformer: new TransformerVarchar() })
  str: VARCHAR_PG = "";

  @Column({ transformer: new TransformerInteger() })
  num_4: INTEGER_PG = -1;

  @Column({ transformer: new TransformerBigInteger() })
  num_8: BIGINT_PG = Math.floor(new Date().getTime()).toString();

  @Column({ transformer: new TransformerBoolean() })
  boolean_default: boolean = false;
}
